
//
//  UIBarButtonItem+Extensions.swift
//  飞哥微博
//
//  Created by gary.liu on 16/12/25.
//  Copyright © 2016年 gary.liu. All rights reserved.
//

import Foundation

extension UIBarButtonItem {
    
    
    /// 创建 UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize 默认 16 号
    ///   - target: target
    ///   - action: action
    convenience init(title:String, fontSize:CGFloat = 16, target:Any?, action:Selector, isBack:Bool = false) {
        
        let btn:UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        if isBack {
            let imageName = "navigationbar_back_withtext"
            
            btn.setImage(UIImage(named: imageName), for: UIControlState(rawValue: 0))
            btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
            
            btn.sizeToFit()
        }
        
        // self.init 实例化 UIBarButtonItem
        self.init(customView: btn)
    }
    
}
